package com.example.starter.work5
import io.vertx.core.AbstractVerticle
import mu.KotlinLogging
import org.apache.rocketmq.client.producer.DefaultMQProducer
import org.apache.rocketmq.common.message.Message
import java.text.SimpleDateFormat
import java.util.*

class ProducerVerticle : AbstractVerticle() {
  private val logger = KotlinLogging.logger {}
  override fun start() {
    val producer = DefaultMQProducer("Msg1")
    producer.namesrvAddr = "192.168.201.129:9876"

    producer.start()
    vertx.setPeriodic(1000) {
      val message1 = Message("topic", "tags", ("Hello, RocketMQ1").toByteArray())
      val message2 = Message("topic", "tags", ("Hello, RocketMQ2").toByteArray())
      message1.delayTimeLevel=4
      message2.delayTimeLevel=5
      producer.send(message1,53*1000)
      producer.send(message2,67*1000)
      //Log.d("Message sent to RocketMQ")
      val currentTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())
      logger.debug(currentTime.toString()+"Message sent to RocketMQ")
     // producer.shutdown()
    }

  }
}





